/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package admin.reportes;

import DBMS.DataBaseManager;
import admin.permisos.PermisosManager;
import clases.Reporte;
import clases.Usuario;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author fjgimon
 */
public class CargarReporte extends org.apache.struts.action.Action {

    private String ALL = "all";
    private static final String name = "Cargar Reporte";
    private static final String FAILURE = "FAILURE";

    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
//        Usuario usr = (Usuario) request.getSession().getAttribute("logueado");
//        DataBaseManager dbms = DataBaseManager.getInstance();
//        if (!PermisosManager.validar(this.name, dbms.consultarPermisoAccion(name), usr.getPermiso())) {
//            System.out.println("No tiene permiso");
//            return mapping.findForward(FAILURE);
//        }
        DataBaseManager dbms = DataBaseManager.getInstance();
        Reporte r = (Reporte) form;
        String idreporte = (String) request.getParameter("idrep");
//        DataBaseManager dbms = DataBaseManager.getInstance();
        ArrayList<Reporte> reportes = dbms.consultarReportes();
        System.out.println("idreporte" + idreporte);
        r.setIdreporte(Integer.parseInt(idreporte));
        r = dbms.consultarReporte(r);
        if (r != null) {
            r.setReporte(dbms.consultarElementosReporte(r));
        }
        request.setAttribute("reporte", r);
        request.setAttribute("reportes", reportes);
        return mapping.findForward(ALL);
    }
}
